package org.ipb.controller.modul.kelompokorganisasi;

import org.ipb.model.KelompokOrganisasi;

import util.hibernate.DAO;
import com.opensymphony.xwork2.ActionSupport;

public class ActionJQGridCrud extends ActionSupport {
	private static final long serialVersionUID = -5933849517817526086L;
	private String id;
	private String nama;
	private String oper;

	public String getOper() {
		return oper;
	}

	public void setOper(String oper) {
		this.oper = oper;
	}

	public String execute() {
		if (getOper().equals("edit")) {
			return update();
		} else if (getOper().equals("add")) {
			return insert();
		} else {
			return delete();
		}
	}

	public String insert() {
		DAO<Integer> dao = new DAO<Integer>();
		KelompokOrganisasi object = new KelompokOrganisasi();
		object.setNama(getNama());
		dao.insert(object);
		dao.close();
		return SUCCESS;
	}

	public String update() {
		DAO<Integer> dao = new DAO<Integer>();
		KelompokOrganisasi update = (KelompokOrganisasi) dao.find(
				KelompokOrganisasi.class, Integer.valueOf(getId()));
		update.setNama(getNama());
		dao.update(update);
		dao.close();
		return SUCCESS;
	}

	public String delete() {
		DAO<Integer> dao = new DAO<Integer>();

		KelompokOrganisasi delete = (KelompokOrganisasi) dao.find(
				KelompokOrganisasi.class, Integer.valueOf(getId()));
		dao.delete(delete);
		dao.close();
		return SUCCESS;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getNama() {
		return nama;
	}

	public void setNama(String nama) {
		this.nama = nama;
	}

}
